
package com.waitingsnow.common.share.qqMicroBlog.support
{
	/**
	 * 微博相关的实用工具类，全部是静态方法
	 * @langversion 3.0
	 * @playerversion Flash 9
	 * @playerversion AIR 1.1
	 */	
	public class WeiboUtil
	{
		/**
		 * 获取指定长度的随机字符串
		 * @param length 指定获取多少个随机字符
		 * @return 指定长度的随机字符串
		 * 
		 */		
		public static function getRandomChars(length:uint):String
		{
			var charsSource:String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
			var randomChar:String = "";
			for (var i:int = 0; i < length; i++) 
			{
				var index:int = int(Math.random()*charsSource.length);
				randomChar += charsSource.charAt(index);
			}
			return randomChar;
		}
		/**
		 * 获取时间戳
		 * @return 返回自1970至今的秒数
		 */		
		public static function getTimestamp():int
		{
			var date:Date = new Date();
			return int(date.getTime()/1000);
		}
		/**
		 * 将一个对象转换为URL参数
		 * @param parms 包含参数的对象
		 * @return 符合URL规范的字符串
		 * 
		 */		
		public static function parseObj2URLString(parms:Object):String
		{
			var parmsArr:Array = [];
			for(var parmName:String in parms)
			{
				parmsArr.push({name:parmName,value:parms[parmName]});
			}
			parmsArr.sortOn("name");
			var sortedParams:Array = [];
			for each(var item:Object in parmsArr)
			{
				sortedParams.push(item.name+"="+item.value);
			}
			var sortedParamsString:String = sortedParams.join("&");
			return sortedParamsString;
		}
		/**
		 * 合并对象参数到一个对象
		 * @param args 若干对象
		 * @return 一个对象
		 * 
		 */		
		public static function margeObjects(...args):Object
		{
			var obj:Object = {};
			for each(var item:Object in args)
			{
				for(var parmName:String in item)
				{
					obj[parmName] = item[parmName];
				}
			}
			return obj;
		}
	}
}